package com.ruoyi.web.controller.sale;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.FreightMethod;
import com.ruoyi.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sale.service.IFreightMethodService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 货运方式Controller
 * 
 * @author ruoyi
 * @date 2023-10-17
 */
@RestController
@RequestMapping("/sale/FreightMethod")
public class FreightMethodController extends BaseController
{
    @Autowired
    private IFreightMethodService freightMethodService;

    /**
     * 查询货运方式列表
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:list')")
    @GetMapping("/list")
    public TableDataInfo list(FreightMethod freightMethod)
    {
        startPage();
        List<FreightMethod> list = freightMethodService.selectFreightMethodList(freightMethod);
        return getDataTable(list);
    }

    /**
     * 导出货运方式列表
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:export')")
    @Log(title = "货运方式", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FreightMethod freightMethod)
    {
        List<FreightMethod> list = freightMethodService.selectFreightMethodList(freightMethod);
        ExcelUtil<FreightMethod> util = new ExcelUtil<FreightMethod>(FreightMethod.class);
        util.exportExcel(response, list, "货运方式数据");
    }

    /**
     * 获取货运方式详细信息
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(freightMethodService.selectFreightMethodById(id));
    }

    /**
     * 新增货运方式
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:add')")
    @Log(title = "货运方式", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FreightMethod freightMethod)
    {
        return toAjax(freightMethodService.insertFreightMethod(freightMethod));
    }

    /**
     * 修改货运方式
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:edit')")
    @Log(title = "货运方式", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FreightMethod freightMethod)
    {
        return toAjax(freightMethodService.updateFreightMethod(freightMethod));
    }

    /**
     * 删除货运方式
     */
    @PreAuthorize("@ss.hasPermi('sale:FreightMethod:remove')")
    @Log(title = "货运方式", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(freightMethodService.deleteFreightMethodByIds(ids));
    }
}
